package cn.iocoder.yudao.module.member.vip.api;

import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.api.member.vip.VipUserApi;
import cn.iocoder.yudao.module.api.member.vip.enums.VipTypeEnum;
import cn.iocoder.yudao.module.api.member.vip.vo.VipUserSummaryVO;
import cn.iocoder.yudao.module.api.member.vip.vo.VipUserVO;
import cn.iocoder.yudao.module.member.vip.dal.dataobject.VipUserDO;
import cn.iocoder.yudao.module.member.vip.service.AppVipUserService;
import jakarta.annotation.Nullable;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

/**
 * 会员用户的 API 实现类
 *
 * @author 山野羡民
 */
@Service
@Validated
public class VipUserApiImpl implements VipUserApi {

    @Resource
    private AppVipUserService appVipUserService;

    @Override
    public VipUserVO getVipUser(Long userId) {
        VipUserDO vipUserDO = appVipUserService.getOrCreate(userId);
        return BeanUtils.toBean(vipUserDO, VipUserVO.class);
    }

    @Override
    public boolean validVip(Long userId, @Nullable VipTypeEnum vipType) {
        return appVipUserService.isValid(userId, vipType);
    }

    @Override
    public VipUserSummaryVO getVipSummaryByShopId(Long shopId) {
        return appVipUserService.getVipSummaryByBindShopId(shopId);
    }

}
